package com.usian.controller;

import com.usian.feign.SSOFeign;
import com.usian.pojo.TbUser;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/frontend/sso")
public class SSOWebController {

    @Autowired
    SSOFeign ssoFeign;

    /**
     * 更新用户过期时间
     *
     * @param token
     * @return
     */
    @RequestMapping("getUserByToken/{token}")
    public Result getUserByToken(@PathVariable String token){
        boolean bool = ssoFeign.getUserByToken(token);
        if (bool){
            return Result.ok("OK");
        }
        return Result.error("过期时间更新失败");
    }

    /**
     * 用户退出接口
     *
     * @param token
     * @return
     */
    @RequestMapping("logOut")
    public Result logOut(String token){
       boolean bool = ssoFeign.logOut(token);
       if (bool){
           return Result.ok("退出成功");
       }
       return Result.error("退出失败");
    }

    /**
     * 用户登录接口
     *
     * @param username
     * @param password
     * @return
     */
    @RequestMapping("userLogin")
    public Result userLogin(@RequestParam String username,@RequestParam String password){
        Map map = ssoFeign.userLogin(username,password);
        if (map.size() > 0){
            return Result.ok(map);
        }
        return Result.error("登录失败");
    }

    /**
     * 注册验证接口
     *
     * @param checkValue
     * @param checkFlag
     * @return
     */
    @RequestMapping("checkUserInfo/{checkValue}/{checkFlag}")
    public Result checkUserInfo(@PathVariable String checkValue,@PathVariable Integer checkFlag){
       boolean result =  ssoFeign.checkUserInfo(checkValue,checkFlag);
       if (result){
           return Result.ok("OK");
       }
       return Result.error("校验失败");
    }

    /**
     * 用户注册接口
     *
     * @param tbUser
     * @return
     */
    @RequestMapping("userRegister")
    public Result userRegister(TbUser tbUser){
       Map result =  ssoFeign.userRegister(tbUser);
        if (result.size() > 0){
            return Result.ok(result);
        }
        return Result.error("校验失败");
    }
}
